package integrationTier;

import integrationTier.sql.MediumSQLDAO;
import integrationTier.sql.GenreSQLDAO;
import integrationTier.sql.DatabaseSQLDAO;
import integrationTier.sql.MovieSQLDAO;
import core.MovieException;
import java.sql.Connection;
import java.sql.DriverManager;

/**
 * Trida vracejici SQL objekty pro pristup k DAO objektum
 * @author vojta
 */
public class SQLDAOFactory extends AbstractDAOFactory {

    static Connection cn;
    static String username;
    static String password;
    static String file;
   
    public SQLDAOFactory(String soubor, String username, String password) throws MovieException {
        try {
            Class.forName("org.hsqldb.jdbcDriver");
            cn = DriverManager.getConnection("jdbc:hsqldb:file:" + soubor, username, password); //username "sa" pass ""                                 
        } catch (Exception ex) {
            throw new MovieException(ex);
        }
    }

    @Override
    public IGenreDAO getGenreDAO() throws MovieException {
        return new GenreSQLDAO(cn);
    }

    @Override
    public IMediumDAO getMediumDAO() throws MovieException {
        return new MediumSQLDAO(cn);
    }

    @Override
    public IDatabaseDAO getDatabaseDAO() throws MovieException {
        return new DatabaseSQLDAO(cn);
    }

    @Override
    public IMovieDAO getMovieDAO() throws MovieException {
        return new MovieSQLDAO(cn);
    }

  
}
